package com.demo.service.impl;

import com.demo.common.utils.AuthUtils;
import com.demo.mapper.ClueMapper;
import com.demo.vo.ClueRemarkVo;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.demo.entity.ClueRemark;
import com.demo.mapper.ClueRemarkMapper;
import com.demo.service.ClueRemarkService;

import java.util.Date;
import java.util.List;

@Service
public class ClueRemarkServiceImpl extends ServiceImpl<ClueRemarkMapper, ClueRemark> implements ClueRemarkService {

    @Autowired
    private ClueRemarkMapper clueRemarkMapper;

    @Override
    public PageInfo<ClueRemarkVo> queryClueRemarkListByPage(Integer current, Integer pageSize, Integer clueId) {
        PageHelper.startPage(current, pageSize);
        List<ClueRemarkVo> list = clueRemarkMapper.selectListByClueId(clueId);
        return new PageInfo<>(list);
    }

    @Override
    public Boolean saveClueRemark(ClueRemark clueRemark) {
        clueRemark.setCreateBy(AuthUtils.getLoginUserId());
        clueRemark.setCreateTime(new Date());
        clueRemark.setDeleted(0);
        int result = clueRemarkMapper.insert(clueRemark);
        return result > 0;
    }

    @Override
    public Boolean updateClueRemark(ClueRemark clueRemark) {
        clueRemark.setEditBy(AuthUtils.getLoginUserId());
        clueRemark.setEditTime(new Date());
        int result = clueRemarkMapper.updateById(clueRemark);
        return result > 0;
    }

    @Override
    public Boolean removeClueRemark(Integer id) {
        ClueRemark clueRemark = new ClueRemark();
        clueRemark.setId(id);
        clueRemark.setDeleted(1); // 删除状态（0正常，1删除）
        clueRemark.setEditBy(AuthUtils.getLoginUserId());
        clueRemark.setEditTime(new Date());
        return clueRemarkMapper.updateById(clueRemark) > 0;
    }
}
